package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.DeliveryAddress;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeliveryAddressMapper {

    /**
     * 读取用户地址
     * @param userId 用户ID
     * @return 用户地址集合
     */
    @Select("select * from deliveryaddress where userId=#{userId}")
    public List<DeliveryAddress> readAddress(Integer userId) throws Exception;

    /**
     * 根据地址Id查询地址
     * @param daId
     * @return
     * @throws Exception
     */
    @Select("select * from deliveryaddress where daId=#{daId}")
    public DeliveryAddress getDeliveryAddressById(Integer daId) throws Exception;

    /**
     * 更新地址信息
     * @param daId
     * @param contactName
     * @param contactSex
     * @param contactTel
     * @param address
     * @param userId
     * @return
     */
    @Update("update deliveryaddress set contactName=#{contactName} and contactSex=#{contactSex} and" +
            " contactTel=#{contactTel} and address=#{address} and userId=#{userId} where daId=#{daId}")
    public int reviseDeliveryAddress(Integer daId,
                                     String contactName,
                                     Integer contactSex,
                                     String contactTel,
                                     String address,
                                     Integer userId) throws Exception;

    /**
     * 删除对应地址
     * @param daId
     * @return
     * @throws Exception
     */
    @Delete("delete from deliveryaddress where daId=#{daId}")
    public int deleteDeliveryAddress(Integer daId) throws Exception;

    /**
     * 新增对应地址
     * @param contactName
     * @param contactSex
     * @param contactTel
     * @param address
     * @param userId
     * @return
     * @throws Exception
     */
    @Insert("insert into cart(contactName,contactSex,contactTel,address,userId) " +
            "values(#{contactName},#{contactSex},#{contactTel},#{address},#{userId})")
    public int saveDeliveryAddress(String contactName,
                                   Integer contactSex,
                                   String contactTel,
                                   String address,
                                   Integer userId) throws Exception;
}
